package pl.maliboo.ftp.invokers {
	
	import pl.maliboo.ftp.Commands;
	import pl.maliboo.ftp.FTPCommand;
	import pl.maliboo.ftp.Responses;
	import pl.maliboo.ftp.core.FTPClient;
	import pl.maliboo.ftp.core.FTPInvoker;
	import pl.maliboo.ftp.errors.InvokeError;
	import pl.maliboo.ftp.events.FTPEvent;


	public class DeleteInv extends FTPInvoker {
	
		private var file:String;
		
		public function DeleteInv(client:FTPClient, file:String) {
			super(client);
			this.file = file;
		}
		
		override protected function startSequence():void {
			sendCommand(new FTPCommand(Commands.DELETE, file));
		}
		
		override protected function responseHandler(evt:FTPEvent):void {
			
			switch (evt.response.code) {
				case Responses.FILE_ACTION_OK:
					var deleteEvent:FTPEvent = new FTPEvent(FTPEvent.DELETE_FILE);
					release(deleteEvent);
				break;
				
				default:
					releaseWithError(new InvokeError(evt.response.message));
			}
		}
		
		override protected function cleanUp():void { }
		
	}
}